/*
 * Publisher.java
 *
 * Created on May 12, 2006, 2:45 AM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

/**
 *
 * @author jtma
 */

import java.sql.SQLException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.regex.*;
import java.util.StringTokenizer;


public class Publisher {
    
    private String _outputfile;
    
    /** Creates a new instance of Publisher */
    public Publisher(String filename) {
        _outputfile = filename;
    }

    private void dump(String str)
    {
        try {
            PrintWriter pw = new PrintWriter(new FileOutputStream(_outputfile, true));
            pw.println(str);
            pw.close();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }

    }
    
    public void publishScores(Database db)
    {
        //temporary store diff time
        long tempTime=globalData.diffTime;
            
      // Barehand
        String tempOutputFile = _outputfile;
        new File(_outputfile).delete();

        dump("<html>");
            
            dump("<head>");
                dump("<title>");
                    dump("Final Report");
                dump("</title>");
            dump("</head>");

            dump("<body>");
                dump("<pre>");
                
                //print report
                dump(db.getReport());

                //print athlete order
                dump(db.getAthleteOrder());
                
                //print athlete nandu
                dump(db.getAthletesNandu());
        
                dump("</pre>");
           dump("</body>");
               
        dump("</html>");
        
        _outputfile = "..\\data\\EventScores.html";
         new File(_outputfile).delete();

        dump("<html>");
            
            dump("<head>");
                dump("<title>");
                    dump("Final Report");
                dump("</title>");
            dump("</head>");

            dump("<body>");
                dump("<pre>");
                
                //print report
                dump(db.getScore());

        
                dump("</pre>");
           dump("</body>");
               
        dump("</html>");
        
        _outputfile = "..\\data\\AthleteOrder.html";
         new File(_outputfile).delete();

        dump("<html>");
            
            dump("<head>");
                dump("<title>");
                    dump("Final Report");
                dump("</title>");
            dump("</head>");

            dump("<body>");
                dump("<pre>");
                
                //print athlete order
                dump(db.getAthleteOrder());
        
                dump("</pre>");
           dump("</body>");
               
        dump("</html>");
        
        _outputfile = "..\\data\\AthletesNandu.html";
        new File(_outputfile).delete();

        dump("<html>");
            
            dump("<head>");
                dump("<title>");
                    dump("Final Report");
                dump("</title>");
            dump("</head>");

            dump("<body>");
                dump("<pre>");
                
                //print athlete nandu
                dump(db.getAthletesNandu());
        
                dump("</pre>");
           dump("</body>");
               
        dump("</html>"); 
        //restore diffTime
        globalData.diffTime=tempTime;
    }
    
    public void publishScoresSimple(Database db)
    {
        //temporary store diff time
        long tempTime=globalData.diffTime;
            
      // Barehand
        new File(_outputfile).delete();

        dump("<html>");
            
            dump("<head>");
                dump("<title>");
                    dump("Final Report");
                dump("</title>");
            dump("</head>");

            dump("<body>");
                dump("<pre>");
                
                //print report
                dump(db.getReportSimple());

                ////print athlete order
                //dump(db.getAthleteOrderSimple());
                
                //print athlete nandu
                //dump(db.getAthletesNandu());
        
                dump("</pre>");
           dump("</body>");
               
        dump("</html>");
        
//        _outputfile = "..\\data\\EventScoresSimple.html";
//         new File(_outputfile).delete();
//
//        dump("<html>");
//            
//            dump("<head>");
//                dump("<title>");
//                    dump("Final Report");
//                dump("</title>");
//            dump("</head>");
//
//            dump("<body>");
//                dump("<pre>");
//                
//                //print report
//                dump(db.getScore());
//
//        
//                dump("</pre>");
//           dump("</body>");
//               
//        dump("</html>");
//        
//        _outputfile = "..\\data\\AthleteOrderSimple.html";
//         new File(_outputfile).delete();
//
//        dump("<html>");
//            
//            dump("<head>");
//                dump("<title>");
//                    dump("Final Report");
//                dump("</title>");
//            dump("</head>");
//
//            dump("<body>");
//                dump("<pre>");
//                
//                //print athlete order
//                dump(db.getAthleteOrder());
//        
//                dump("</pre>");
//           dump("</body>");
//               
//        dump("</html>");
//        
//        _outputfile = "..\\data\\AthletesNanduSimple.html";
//        new File(_outputfile).delete();
//
//        dump("<html>");
//            
//            dump("<head>");
//                dump("<title>");
//                    dump("Final Report");
//                dump("</title>");
//            dump("</head>");
//
//            dump("<body>");
//                dump("<pre>");
//                
//                //print athlete nandu
//                dump(db.getAthletesNandu());
//        
//                dump("</pre>");
//           dump("</body>");
//               
//        dump("</html>"); 
        //restore diffTime
        globalData.diffTime=tempTime;
    }
}
